<template>
    <view class="form_container">
        <view class="page-body">
                <view class="uni-padding-wrap uni-common-mt">
                    <view class="uni-title uni-common-mt">
                        示例 1
                        <text>\nmovable-view 区域小于 movable-area</text>
                    </view>
                    <movable-area>
                        <movable-view :x="x" :y="y" direction="all" @change="onChange">text</movable-view>
                    </movable-area>
                    <view @tap="tap" class="uni-link uni-center uni-common-mt">
                        点击这里移动至 (30px, 30px)
                    </view>
                    <view class="uni-title uni-common-mt">
                        示例 2
                        <text>\nmovable-view区域大于movable-area</text>
                    </view>
                    <movable-area>
                        <movable-view class="max" direction="all">text</movable-view>
                    </movable-area>
                </view>
            </view>
    </view>
</template>

<script>

export default {
  data() {
    return {
      setting: null,
      x: 0,
      y: 0,
      old: {
          x: 0,
          y: 0
      }
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    // uni.setNavigationBarColor({
    //   frontColor: '#ffffff',
    //   backgroundColor: '#59bfba'
    // });
    that.getData(that.params);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getData(this.params);
    uni.showNavigationBarLoading();
    uni.hideNavigationBarLoading(); //完成停止加载

    uni.stopPullDownRefresh(); //停止下拉刷新
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },
  methods: {
    tap: function(e) {
        this.x = this.old.x
        this.y = this.old.y
        this.$nextTick(function() {
            this.x = 30
            this.y = 30
        })
    },
    onChange: function(e) {
        this.old.x = e.detail.x
        this.old.y = e.detail.y
    },
    tolinkUrlFun:function(url){
        if(url){
            uni.navigateTo({
              url: '/pages/'+url+'/index'
            });
        }
    },
    /* 获取数据 */
    getData: function (param) {
      var customIndex = getApp().globalData.AddClientUrl("/more_product_list.html", param);
      getApp().globalData.showToastLoading('loading', true);
      var that = this;
      uni.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          uni.hideLoading();
          console.log(res.data);
          uni.hideLoading();
        },
        fail: function (res) {
          console.log("fail");
          uni.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>